package com.fuhaiwei.domain.interceptor;

import java.lang.reflect.Method;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

public abstract class AbstractLogInterceptor implements MethodInterceptor {

	public abstract Object invoke(MethodInvocation invocation) throws Throwable;

	public String getMethodString(MethodInvocation invocation) {
		return getMethodString(invocation.getMethod(),
				invocation.getArguments());
	}

	public String getMethodString(Method method, Object[] arguments) {
		StringBuilder sb = new StringBuilder();
		sb.append(method.getName());
		sb.append("(");
		for (int i = 0; i < arguments.length; i++) {
			sb.append(arguments[i]);
			if (i < arguments.length - 1) {
				sb.append(", ");
			}
		}
		sb.append(")");
		return sb.toString();
	}

}
